// 
//  Copyright 2011  comphilip
// 
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
// 
//        http://www.apache.org/licenses/LICENSE-2.0
// 
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;

namespace Dict4Engkoo.Engkoo {
	internal class Thesaurus {
		private JToken _token;
		public Thesaurus(JToken Token){
			_token = Token;
		}
		
		public string Character {
			get {
				JToken pos = _token["$POS"];
				return pos != null ? pos.Value<string>() : string.Empty;
			}
		}
		
		public IEnumerable<string> Synonyms{
			get {
				return GetThesaurus("S");
			}
		}
		
		public IEnumerable<string> Antonyms{
			get{
				return GetThesaurus("A");
			}
		}
		
		private IEnumerable<string> GetThesaurus(string ThesaurusType){
			JToken synonym = _token[ThesaurusType];
				if (synonym == null)
					yield break;
				JArray array = synonym as JArray;
				if (array != null)
					foreach(var item in array)
						yield return Uri.UnescapeDataString(item["$"].Value<string>());
				else
					yield return Uri.UnescapeDataString(synonym["$"].Value<string>());
		}
	}
}

